#!/usr/bin/env python
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.2')

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from model import LectureM


class lectureHandler(webapp.RequestHandler):
    def post(self):
        name = self.request.get("name")
        courseKey = self.request.get("courseKey")
        if name and courseKey:
            result = LectureM.addLecture(name, courseKey)
            if isinstance(result, basestring):
                self.response.out.write(result)#error
            elif isinstance(result, LectureM.Lecture):
                self.redirect("/lecture?key=" + str(result.key()))
        else:
            pass

application = webapp.WSGIApplication([(r'.*', lectureHandler)],debug=True)

def main():
    run_wsgi_app(application)
    
if __name__ == '__main__':
    main()